using System;
using System.Globalization;
using Prometheus.TypeUtility;

namespace Prometheus.Binding.ReadOnly.BaseConverters
{
    public class proSecondsToTimeSpanString : proChainConverter
    {
        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is double)
            {
                var secs = (double) value;
                return TimeSpan.FromSeconds(secs).ToHHMMSS();
            }
            return value;
        }

        public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is TimeSpan)
            {
                var ts = (TimeSpan) value;
                return ts.TotalSeconds;
            }
            return value;
        }
    }
}